package com.ts.service.achievement.impl;

import com.ts.constant.AchievementStatusConstant;
import org.springframework.beans.factory.annotation.Autowired;
import com.ts.constant.AchievementConstant;
import com.ts.constant.StatusConstant;
import com.ts.entity.TsAchievement;

import com.ts.mapper.achievement.TsAchievementMapper;
import com.ts.service.achievement.TsAchievementService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.time.LocalDateTime;

@Service
public class TsAchievementServiceImpl implements TsAchievementService {
    @Autowired
    private TsAchievementMapper tsAchievementMapper;
    @Transactional
    @Override
    public TsAchievement addAchievement(String name, String description, String type, Integer level, Integer createdBy, Long detailId) {
        TsAchievement achievement = new TsAchievement();
        // 前端传入字段
        achievement.setName(name);
        achievement.setDescription(description);
        achievement.setLevel(level);
        achievement.setType(type);// 或根据业务动态设置（如论文对应PAPER）
        // 常量默认值
        achievement.setStatus(StatusConstant.STATUS_UNDER_REVIEW);
        // 关联详情ID（关键：接收paperId并设置到detail_id）
        achievement.setDetailId(detailId);
        // 系统自动填充字段
        LocalDateTime now = LocalDateTime.now();
        achievement.setCreatedTime(now);
        achievement.setUpdatedTime(now);
        achievement.setCreatedBy(createdBy);
        achievement.setUpdatedBy(createdBy);

        tsAchievementMapper.insert(achievement);
        return achievement;
    }
}
